package br.com.edumobi.activities;

import android.content.Intent;
import android.os.Bundle;

import java.util.List;

import br.com.edumobi.R;
import br.com.edumobi.dados.modelos.Classificacao;
import br.com.edumobi.dados.modelos.Questao;
import br.com.edumobi.fragments.MEQuestoesFragment;

public class MEQuestoesActivity extends GenericaActivity implements MEQuestoesFragment.AcoesMEQuestoesFragment {

    public static final String EXTRA_CLASSIFICACAO = "EXTRA_CLASSIFICACAO";
    public static final String EXTRA_USO_ASSISTENTE = "EXTRA_USO_ASSISTENTE";

    private Intent intentQuestao;

    private static final int REQUEST_CODE_QUESTAO = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_questoes);

        getActionBar().setTitle(((Classificacao) getIntent().getSerializableExtra(EXTRA_CLASSIFICACAO)).nome);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case REQUEST_CODE_QUESTAO:
                intentQuestao = null;
                break;
            default:
                break;
        }
    }

    @Override
    public List<Questao> obterQuestoes() {
        return local.consultarQuestoesPorClassificacao((Classificacao) getIntent().getSerializableExtra(EXTRA_CLASSIFICACAO));
    }

    @Override
    public void abrirQuestao(int indexQuestao) {
        if (intentQuestao == null) {
            intentQuestao = new Intent(this, MEQuestaoActivity.class);
            intentQuestao.putExtra(MEQuestaoActivity.EXTRA_CLASSIFICACAO, getIntent().getSerializableExtra(EXTRA_CLASSIFICACAO));
            intentQuestao.putExtra(MEQuestaoActivity.EXTRA_USO_ASSISTENTE, getIntent().getBooleanExtra(EXTRA_USO_ASSISTENTE, false));
            intentQuestao.putExtra(MEQuestaoActivity.EXTRA_INDEX_QUESTAO_SELECIONADA, indexQuestao);
            startActivityForResult(intentQuestao, REQUEST_CODE_QUESTAO);
        }
        finish();
    }
}